USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-Insert]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	Insert record into table [dbo].[Dealers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-Insert]
	/*@Dealer_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@Dealer_Notes varchar(max) =Null  , 
	@Dealer_StartDate datetime =Null  , 
	@Dealer_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Dealers](/*[Dealer_ID], [Dealer_Code], [DealerType_ID], [Dealer_NameAr], [Dealer_NameEn], [Dealer_Notes], [Dealer_StartDate], [Dealer_Search]*/)
	VALUES     (/*@Dealer_ID, @Dealer_Code, @DealerType_ID, @Dealer_NameAr, @Dealer_NameEn, @Dealer_Notes, @Dealer_StartDate, @Dealer_Search*/)

	/*SELECT @Dealer_RowNumber = [Dealer_RowNumber]
    FROM [dbo].[Dealers]
    WHERE  ( [Dealer_ID] =@Dealer_ID )
	AND  ( [Dealer_Code] =@Dealer_Code )
	AND  ( [DealerType_ID] =@DealerType_ID )
	AND  ( [Dealer_NameAr] =@Dealer_NameAr )
	AND  ( [Dealer_NameEn] =@Dealer_NameEn )
	AND  ( [Dealer_Notes] =@Dealer_Notes )
	AND  ( [Dealer_StartDate] =@Dealer_StartDate )
	AND  ( [Dealer_Search] =@Dealer_Search )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-update]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	Update record in table [dbo].[Dealers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-update]
	/*@Dealer_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@Dealer_Notes varchar(max) =Null  , 
	@Dealer_StartDate datetime =Null  , 
	@Dealer_Search varchar(max) =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[Dealers] SET 
		/*[Dealer_ID] =@Dealer_ID, 
		[Dealer_Code] =@Dealer_Code, 
		[DealerType_ID] =@DealerType_ID, 
		[Dealer_NameAr] =@Dealer_NameAr, 
		[Dealer_NameEn] =@Dealer_NameEn, 
		[Dealer_Notes] =@Dealer_Notes, 
		[Dealer_StartDate] =@Dealer_StartDate, 
		[Dealer_Search] =@Dealer_Search*/
		/*WHERE ([Dealer_ID] = @Dealer_ID)*/
	/**/

	/*SELECT @Dealer_RowNumber = [Dealer_RowNumber]
    FROM [dbo].[Dealers]
	WHERE ([Dealer_ID] = @Dealer_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-Insert-Update]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	Insert OR Update record into table [dbo].[Dealers]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-Insert-Update]
	/*@Dealer_RowNumber int =Null OUTPUT , 
	@Dealer_ID uniqueidentifier =Null  , 
	@Dealer_Code varchar(50) =Null  , 
	@DealerType_ID uniqueidentifier =Null  , 
	@Dealer_NameAr varchar(300) =Null  , 
	@Dealer_NameEn varchar(300) =Null  , 
	@Dealer_Notes varchar(max) =Null  , 
	@Dealer_StartDate datetime =Null  , 
	@Dealer_Search varchar(max) =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Dealers] 
					/*WHERE ([Dealer_ID] = @Dealer_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Dealers](/*[Dealer_ID], [Dealer_Code], [DealerType_ID], [Dealer_NameAr], [Dealer_NameEn], [Dealer_Notes], [Dealer_StartDate], [Dealer_Search]*/)
		VALUES     (/*@Dealer_ID, @Dealer_Code, @DealerType_ID, @Dealer_NameAr, @Dealer_NameEn, @Dealer_Notes, @Dealer_StartDate, @Dealer_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[Dealers] SET 
			/*[Dealer_ID] =@Dealer_ID, 
			[Dealer_Code] =@Dealer_Code, 
			[DealerType_ID] =@DealerType_ID, 
			[Dealer_NameAr] =@Dealer_NameAr, 
			[Dealer_NameEn] =@Dealer_NameEn, 
			[Dealer_Notes] =@Dealer_Notes, 
			[Dealer_StartDate] =@Dealer_StartDate, 
			[Dealer_Search] =@Dealer_Search*/
			/*WHERE ([Dealer_ID] = @Dealer_ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Dealer_RowNumber = [Dealer_RowNumber]
    FROM [dbo].[Dealers]
	WHERE ([Dealer_ID] = @Dealer_ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-Delete]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	delete records from table [dbo].[Dealers] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-Delete]
	/*@Dealer_RowNumber int =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Dealer_Code varchar(50) =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@Dealer_NameAr varchar(300) =null  , 
	@Dealer_NameEn varchar(300) =null  , 
	@Dealer_Notes varchar(max) =null  , 
	@Dealer_StartDate datetime =null  , 
	@Dealer_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Dealers]
	WHERE /*( [Dealer_RowNumber] = ISNULL(@Dealer_RowNumber, [Dealer_RowNumber]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Dealer_Code] like ISNULL(@Dealer_Code, [Dealer_Code]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [Dealer_NameAr] like ISNULL(@Dealer_NameAr, [Dealer_NameAr]) )
	AND ( [Dealer_NameEn] like ISNULL(@Dealer_NameEn, [Dealer_NameEn]) )
	AND ( [Dealer_Notes] like ISNULL(@Dealer_Notes, [Dealer_Notes]) )
	AND ( [Dealer_StartDate] = ISNULL(@Dealer_StartDate, [Dealer_StartDate]) )
	AND ( [Dealer_Search] like ISNULL(@Dealer_Search, [Dealer_Search]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[Dealers-Select]    Script Date: [[20120714223929]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223929]]
-- Description:	select records from table [dbo].[Dealers] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Dealers-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Dealers-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Dealers-Select]
	/*@Dealer_RowNumber int =null  , 
	@Dealer_ID uniqueidentifier =null  , 
	@Dealer_Code varchar(50) =null  , 
	@DealerType_ID uniqueidentifier =null  , 
	@Dealer_NameAr varchar(300) =null  , 
	@Dealer_NameEn varchar(300) =null  , 
	@Dealer_Notes varchar(max) =null  , 
	@Dealer_StartDate datetime =null  , 
	@Dealer_Search varchar(max) =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Dealers]
	WHERE /*( [Dealer_RowNumber] = ISNULL(@Dealer_RowNumber, [Dealer_RowNumber]) )
	AND ( [Dealer_ID] = ISNULL(@Dealer_ID, [Dealer_ID]) )
	AND ( [Dealer_Code] like ISNULL(@Dealer_Code, [Dealer_Code]) )
	AND ( [DealerType_ID] = ISNULL(@DealerType_ID, [DealerType_ID]) )
	AND ( [Dealer_NameAr] like ISNULL(@Dealer_NameAr, [Dealer_NameAr]) )
	AND ( [Dealer_NameEn] like ISNULL(@Dealer_NameEn, [Dealer_NameEn]) )
	AND ( [Dealer_Notes] like ISNULL(@Dealer_Notes, [Dealer_Notes]) )
	AND ( [Dealer_StartDate] = ISNULL(@Dealer_StartDate, [Dealer_StartDate]) )
	AND ( [Dealer_Search] like ISNULL(@Dealer_Search, [Dealer_Search]) )*/
END
GO
-- =============================================
